$(function() {
    validateRule();

});
$.validator.setDefaults({
    submitHandler: function() {
		login();
    }
});

function login() {
    $.modal.loading("正在登录中");
	var username = $("input[name='username']").val();
    var password = $("input[name='password']").val();
    var rememberMe = $("input[name='rememberme']").is(':checked');
    $.ajax({
        type: "post",
        url:  "loginIn",
        data: {
            "username": username,
            "password": password,
            "rememberMe": rememberMe
        },
        success: function(r) {
            if (r.code == 0) {
                location.href = '/index';
            } else {
                $.modal.closeLoading();
            	$(".code").val("");
            	$.modal.msg(r.msg);
            }
        }
    });
}

function validateRule() {
    var icon = "<i class='fa fa-times-circle'></i> ";
    $("#signupForm").validate({
        rules: {
            username: {
                required: true
            },
            password: {
                required: true
            }
        },
        messages: {
            username: {
                required: icon + "请输入您的用户名",
            },
            password: {
                required: icon + "请输入您的密码",
            }
        }
    })
}
